package com.example.shippxy.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.shippxy.constant.Constant;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

@RestController
@RequestMapping("/ship")
public class ShipController {

    @GetMapping("/getShips")
    public JSONObject getShips(){
        return new JSONObject(Constant.ships);
    }

    @GetMapping("/getShipsDetail")
    public JSONObject getShipsDetail(){
        JSONObject jsonObject = new JSONObject();
        Set<Map.Entry<String, JSONObject>> set = Constant.shipsMap.entrySet();
        List<JSONObject> list = new ArrayList<>();
        for (Map.Entry<String,JSONObject> entry: set) {
            list.add(entry.getValue());
        }
        jsonObject.put("data",list);
        jsonObject.put("status",0);
        return jsonObject;
    }

    @PostMapping("/addShip")
    public JSONObject addShip(){
        return new JSONObject();
    }
}
